package KK.net.Data
{
	import KK.Data.ProtocolData;
	
	import flash.utils.ByteArray;

	public class Head extends ProtocolData
	{
		static public const LEN:uint=8;//长度
		
		public var isEncode:uint;
		public var protocolType:uint;
		public var len:uint;
		public var protocolID:uint; 
		
		
		private var bodyLen:int;
		
		
		
		
		/**
		 * 反序列化 
		 * @param byte
		 * 
		 */
		override public function Unserialize(byte:ByteArray):void{
			byte.position=0;
			
			isEncode=byte.readUnsignedByte();
			protocolType=byte.readUnsignedByte();
			len=byte.readUnsignedShort();
			protocolID=byte.readUnsignedShort(); 
		}
		 
		/**
		 * 序列化 
		 * @param byte
		 * 
		 */
		override public function Serialize(byte:ByteArray):void{ 
			byte.position=0;
			byte.writeByte(isEncode);
			byte.writeByte(protocolType);
			byte.writeShort(len);
			byte.writeUnsignedInt(protocolID); 
			
			bodyLen=byte.length;
			
			
//			return byte;
		}
		
		
		/**
		 * 获取大小  
		 * @return 
		 * 
		 */
		override public function getSize():uint{
			return bodyLen;
		}
	}
}